package com.secondHandPlatform;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

// 代码生成器
public class AutoCode {
    public static void main(String[] args) {
        String projectPath = System.getProperty("user.dir");
        FastAutoGenerator.create("jdbc:mysql://12.tcp.cpolar.top:13597/secondhandmarket?characterEncoding=utf-8&useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghai", "root", "123456")
                // 全局配置
                .globalConfig((scanner, builder) -> builder.author("team")
                        .outputDir(projectPath + "/src/main/java"))
                // 包配置
                .packageConfig((scanner, builder) -> builder.parent("com.secondHandPlatform")
                                                            .entity("domain"))
                // 策略配置
                .strategyConfig((scanner, builder) -> builder.addInclude(getTables(scanner.apply("请输入表名，多个英文逗号分隔？所有输入 all")))
                        .entityBuilder().enableLombok().controllerBuilder().enableRestStyle())
                .execute();
    }

    // 处理 all 情况
    public static List<String> getTables(String tables) {
        return "all".equals(tables) ? Collections.emptyList() : Arrays.asList(tables.split(","));
    }
}
